package demo.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TestThread {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        try {
            for(int i=0;i<10;i++){
                //            executorService.execute(new TaskExecuteThread("taskid"+i,"modid"+i));
                Future future = executorService.submit(new TaskExecuteThread("taskid" + i, "modid" + i));
                //if(future.get()==null){//如果Future get返回null，任务完成（注意：这里最好别直接get，因为get会阻塞。可以先将future对象存list，然后等所有线程都执行完后再遍历list，获取get。）
                //System.out.println("任务完成"+"taskid" + i);
                //}
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getCause().getMessage());
        }  finally {
            executorService.shutdown();
        }

    }
}
